/*
 * (C) Copyright 2013 George Daswani (georgedaswani@gmail.com) and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-2.1.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *    George Daswani (georgedaswani@gmail.com)
 */

package am.api.wrapper;

import javax.transaction.Transaction;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import am.api.model.AMCredential;

public class AMConnectionKey {

	private final AMCredential credential;
	private final Transaction transaction;

	public AMConnectionKey(AMCredential credential, Transaction transaction) {
		super();
		this.credential = credential;
		this.transaction = transaction;
	}

	public int hashCode() {
		return new HashCodeBuilder(15, 3).append(credential)
				.append(transaction).toHashCode();
	}

	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}
		AMConnectionKey rhs = (AMConnectionKey) obj;
		return new EqualsBuilder().append(credential, rhs.credential)
				.append(transaction, rhs.transaction).isEquals();
	}

	public String toString() {
		return new ToStringBuilder(this).append("credential", credential)
				.append("transaction", transaction).toString();
	}
}
